import { createStore } from 'vuex'

// 创建一个新的 store 实例
const store = createStore({
  state () {
    return {
      count: 0,
      num: 0
    }
  },
  mutations: {
    increment (state) {
      state.count++
    },
    MUTaddNum (state, params) {
      state.num += params.num
    }
  },
  // 异步属性
  actions: {
    ACTaddnum: function ({ commit }, params) {
      setTimeout(() => {
        commit('MUTaddNum', params)
      }, 1000)
    }
  },
  // 计算属性
  getters: {
    GETaddnum: function (state) {
      state.num += 20
      return state.num
    }
  },
  modules: {}
})

export default store
